<?php
/**
 * Created by PhpStorm.
 * User: zhan
 * Date: 2018/9/30  10:17
 */
namespace app\admin\controller;
use think\Db;
class Popularity extends Common
{
    private $table_admin = '';

    /*
	*	构造函数
	*/
    function __construct()
    {
        parent::__construct();
        $this->table_admin = db('proportion');
    }

    //列表
    public function popularity_lists()
    {

        $list = $this->table_admin->where('tc_type',1)->find();

        if(!empty($list)){
            $this->assign('list', $list);
        }

        return $this->fetch();
    }
 
    //添加
    public function edit()
    {
      
        $id = input('id');
        if(!empty($id)){
            $data = db('proportion')->where('id',$id)->find();
            $this->assign('da', $data);
/*          dump($data);die;*/
        }
       
        return $this->fetch();
    }
    //编辑文章
    public function doedit()
    {
            $id = input('id');
   /*         $tc_type = input('tc_type');*/
            $num = input('num');
/*            $data['tc_price'] = $tc_price;
            $data['tc_type'] = $tc_type;*/
            $data['num'] = $num;
            $data['tc_type'] = 1;
            if(empty($id)){
                //添加
                $data['created_at'] = time();
                $res = $this->table_admin->insert($data);
            }else{ 
                //修改
                $data['update_at'] = time();
                $res = $this->table_admin->where(['id'=>$id])->update($data);
            }
            
            if(empty($res))return json(['msg'=>'更新失败']);
            return json(['msg'=>'更新成功']);
    
    }

    public function del(){

        $id = input('id');

        $res = db('proportion')->delete($id);

        if(empty($res))return json(['msg'=>'更新失败']);
        return json(['msg'=>'更新成功']);
    }

}
